<!DOCTYPE html>
<html>
<head>
  <title>SSE Client</title>
</head>
<body>
  <h1>SSE 实时数据流</h1>
  <div id="output"></div>

  <script>
    const output = document.getElementById('output');
    
    // 创建 SSE 连接
    const eventSource = new EventSource('http://localhost:3000/sse');

    eventSource.onmessage = (e) => {
      const data = JSON.parse(e.data);
      output.innerHTML += `
        <p>${data.time} → Count: ${data.count} | ${data.message}</p>
      `;
    };

    eventSource.onerror = (err) => {
      console.error('SSE Error:', err);
      eventSource.close();
    };
  </script>
</body>
</html>